<?php
namespace User\Controller;

use Think\Page;
use User\Model\FactoryModel;
use User\Model\LotteryModel;
use Wap\Model\StatisticsModel;

class LotteryController extends UserController
{
    private $_project;

    public function __construct()
    {
        $this->_project = 'lottery';
        parent::__construct();
        if (!headers_sent() && // 如果页面头部信息还没有输出
            extension_loaded('zlib') && // 而且php已经加载了zlib扩展
            strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')
        ) //而且浏览器接受GZIP
        {
            ini_set('zlib.output_compression', 'On');
            ini_set('zlib.output_compression_level', '4');
        }
    }

    public function index()
    {
        $lottery = M('redpacket');
        $where['token'] = $this->wxuser['token'];
        $where['status'] = array('NEQ', LotteryModel::STATUS_DELETE);
        $where['keyword'] = $this->_project;
        $count = $lottery->where($where)->count();
        $page = new Page($count, 15);
        $show = $page->show();
        $list = $lottery->where($where)->limit($page->firstRow . ',' . $page->listRows)->order('id desc')
            ->select();
        if (!empty($list)) {
            foreach ($list as &$value) {
                $value['link'] = C('SITE_URL').'/Wap/Lottery/index?id='.$value['id'];
            }
        }
        $this->assign('page', $show);
        $this->assign('list', $list);
        $this->display();
    }

    public function statusLottery()
    {
        $status = I('get.status', LotteryModel::STATUS_ACTIVE, '');
        $where['id'] = I('get.id', "", "");;
        if($status == 'active'){
            M('redpacket')->where($where)->save(array('status' => LotteryModel::STATUS_ACTIVE));
            $message = '发布成功';
        }elseif($status == 'stop'){
            M('redpacket')->where($where)->save(array('status' => LotteryModel::STATUS_STOP));
            $message = '停用成功';
        }else {
            M('redpacket')->where($where)->save(array('status' => LotteryModel::STATUS_DELETE));
            $message = '删除成功';
        }

        $this->success($message, '', true);
    }

    public function edit()
    {
        $id = I('get.id', -1, "");
        $condition['id'] = $id;
        $condition['token'] = $this->wxuser['token'];
        $condition['keyword'] = $this->_project;
        $lottery = M('redpacket')->where($condition)->find();
        $first_lottery = '';
        $lottery_items = array();
        if($id == -1){
            $lottery['title'] = '参与活动赢大奖';
            $lottery['range_date'] = date('Y-m-d H:i:s').' ~ '.date('Y-m-d H:i:s', strtotime('+7 day'));
            $lottery['force_follow'] = LotteryModel::FOLLOW_NO;
            $lottery['force_image'] = '/Public/images/zbxmt.jpg';
            $lottery['share_able'] = 0;
            $lottery['number_limits'] = -1;
            $lottery['per_num'] = 1;
            $lottery['share_play'] = 0;
            $lottery['day_limit'] = -1;
            $lottery['per_num_sum'] = 1;
            $lottery['total_rate'] = 10;
            $lottery['img-background'] = '/Public/images/lottery/bg.jpg';
            $lottery['img-accept'] = '/Public/images/lottery/btn-accept.png';
            $lottery['img-share'] = '/Public/images/lottery/btn-share.png';
            $lottery['img-custom'] = '/Public/images/lottery/btn-contact.png';
            $lottery['custom-choose'] = LotteryModel::CUSTOM_CODE;
            $lottery['img-code'] = '/Public/images/zbxmt.jpg';
            $lottery['img-again'] = '/Public/images/lottery/btn-again.png';
            $lottery['share_title'] = '参与活动赢大奖';
            $lottery['share_desc'] = '轻轻松松就能抽到大奖，积攒多年的人品终于有用了，你也赶紧来抽奖吧！！';
            $lottery['share_img'] = '/Public/images/lottery/share.png';
        }else{
            $lottery['range_date'] = $lottery['startdate'].' ~ '.$lottery['enddate'];
            $lottery['force_follow'] = $lottery['game_time'];
            $lottery['force_image'] = $lottery['picurl'];
            $lottery['day_limit'] = $lottery['reserve'];
            $img_data = json_decode($lottery['desc'], true);
            $lottery['img-background'] = $img_data['img-background'];
            $lottery['img-accept'] = $img_data['img-accept'];
            $lottery['img-share'] = $img_data['img-share'];
            $lottery['img-custom'] = $img_data['img-custom'];
            $lottery['custom-choose'] = $img_data['custom-choose'];
            $lottery['img-code'] = $img_data['img-code'];
            $lottery['custom-link'] = $img_data['custom-link'];
            $lottery['img-again'] = $img_data['img-again'];
            $where_item['redpacket_id'] = $id;
            $where_item['status'] = LotteryModel::ITEM_ACTIVE;
            $lottery_items = M('redpacket_item')->where($where_item)->order('id asc')->select();
            $first_lottery = $lottery_items[0]['id'];     //第一个奖项的id，编辑时需要
        }
        //dump($lottery);exit;
        $levels = LotteryModel::getLevel('all');
        $this->assign('id', $id);
        $this->assign('lottery', $lottery);
        $this->assign('f', $first_lottery);
        $this->assign('lottery_items', $lottery_items);
        $this->assign('levels', $levels);
        $this->display();
    }

    public function update()
    {
        $id = I('post.id', -1, '');
        $award_num = I('post.award_num', -1, '');
        $date = I('post.range_date', date('Y-m-d H:i:s').'~'.date('Y-m-d H:i:s', strtotime('+7 day')), '');
        $date = explode('~', $date);
        $force_follow = I('post.force_follow', '', '');
        $share_able = I('post.share_able', '', '');
        $custom_choose = I('post.custom-choose', LotteryModel::CUSTOM_CODE, '');
        $data = array(
            'keyword' => $this->_project,
            'token' => $this->wxuser['token'],
            //step1
            'title' => I('post.title', '', ''),
            'startdate' => $date[0],
            'enddate' => $date[1],
            'info' => I('post.info', '', ''),
            'game_time' => ($force_follow == 'on') ? LotteryModel::FOLLOW_YES : LotteryModel::FOLLOW_NO,  //强制关注
            'picurl' => ($force_follow == 'on') ? I('post.force_image', '', '') : '', //强制关注二维码
            'share_able' => ($share_able == 'on') ? 1 : 0,  //强制关注
            'number_limits' => I('post.number_limits', -1, ''),                        //每日游戏次数上限
            'per_num' => I('post.per_num', 1, ''),                                    //每人每日游戏次数上限
            'share_play' => I('post.share_play', 0, ''),                              //分享奖励次数
            'reserve' => I('post.day_limit', -1, ''),                                 //每日中奖次数上限
            'per_num_sum' => I('post.per_num_sum', 1, ''),                            //每人中奖次数
            'total_rate' => I('post.total_rate', 0, ''),                              //总中奖率
            //step3
            'share_title' => I('share_title', ''),
            'share_desc' => I('share_desc', ''),
            'share_link' => I('share_link', ''),
            'share_img' => I('share_img', '')
        );
        $img_data = array(
            'img-background' => I('post.img-background', '', ''),                   //背景
            'img-accept' => I('post.img-accept', '', ''),                           //去领奖
            'img-share' => I('post.img-share', '', ''),                             //分享
            'img-custom' => I('post.img-custom', '', ''),                           //按钮图片
            'custom-choose' => $custom_choose,                                  //按钮动作
            'img-code' => ($custom_choose == LotteryModel::CUSTOM_CODE) ?  I('post.img-code', '', '') : '', //关注二维码
            'custom-link' => ($custom_choose == LotteryModel::CUSTOM_LINK) ? I('post.custom-link', '', '') : '', //链接地址
            'img-again' => I('post.img-again', '', ''),                             //再玩一次
        );
        $data['desc'] = json_encode($img_data);
        $lottery = M('redpacket');
        if($id == -1){
            $data['createdate'] = date('Y-m-d H:i:s');
            $data['status'] = LotteryModel::STATUS_STOP;
            $lottery_updated = $lottery->add($data);
            $lottery_id = $lottery_updated;
        }else{
            $data['id'] = $id;
            $lottery_updated = $lottery->save($data);
            $lottery_id = $id;
        }
        if($lottery_updated !== false){
            //插入奖项 step2
            $lottery_item = M('redpacket_item');
            if($award_num >= 1) {
                //$upload = $this->_upload($award_num);

                for ($i = 1; $i <= $award_num; $i++) {
                    $item_id = I('post.item_id' . $i, -1, '');
                    $data = array(
                        'redpacket_id' => $lottery_id,
                        'name' => I('post.name' . $i, '', ''),
                        'level' => I('post.level' . $i, '', ''),
                        'number' => I('post.number' . $i, '', ''),
                        'status' => LotteryModel::ITEM_ACTIVE,
                        //'pic' => ($award_num == 1) ? $upload : $upload[$i]
                    );
                    if($item_id > 0){
                        $data['id'] = $item_id;
                        $lottery_prize_id = $lottery_item->save($data);
                    }else{
                        $lottery_prize_id = $lottery_item->add($data);
                    }
                }
                $this->success('保存成功', '/User/Lottery/index');
            }else{
                $this->success('保存成功', '/User/Lottery/index');
            }
        }else{
            $this->error( '保存失败', '/User/Lottery/index');
        }
    }
    //todo 6个盘还是8个盘
    public function uploadFile()
    {
        $img = I('post.img', '', '');
        //$type = I('post.type', '');
        $ret = FactoryModel::ajaxImgUpload($img, 'lottery');
        if($ret['code'] == -1){
            $this->ajaxReturn(array('code' => -1, 'errMsg' => 'img upload fail'));
        }
        $this->ajaxReturn(array('code' => 0, 'msg' => $ret['msg']));
    }

    private function _upload($num)
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728;// 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg', 'mp3', 'mp4', 'wav');// 设置附件上传类型
        $upload->rootPath = './Public/Uploads/lottery/'; // 设置附件上传根目录
        $upload->subName = array('date', 'Ymd');
        $upload->saveName = array('uniqid', 'lottery');
        $info = $upload->upload();
        if($num == 1){
            if($info['picurl1']['savename']){
                $picurl = '/Public/Uploads/lottery/' . date('Ymd') . '/' . $info['picurl1']['savename'];
            }else{
                $picurl = I('post.pic1', '', '');
            }
        }else{
            for($i=1; $i<=$num; $i++){
                if($info['picurl'.$i]['savename']){
                    $picurl[$i] = '/Public/Uploads/lottery/' . date('Ymd') . '/' . $info['picurl'.$i]['savename'];
                }else{
                    $picurl[$i] = I('post.pic'.$i, '', '');
                }
            }
        }
        return $picurl;
    }

    public function deleteAward()
    {
        $where['id'] = I('get.id', -1, '');
        $updated = M('redpacket_item')->where($where)->save(array('status' => LotteryModel::ITEM_DELETE));
        if($updated !== false){
            $this->success('删除奖项成功', '', true);
        }else{
            $this->error('删除奖项失败', '', true);
        }
    }

    public function awardList()
    {
        $id = I('get.id', -1, '');
        $where_lottery['id'] = $id;
        $lottery = M('redpacket')->where($where_lottery)->field('title')->find();
        $query = I('get.query', '', '');
        if(!empty($query)){
            $where_son1['fans.name'] = array('LIKE', '%' . $query . '%');
            $where_son2['fans.phone'] = array('LIKE', '%' . $query . '%');
            $where['_complex'] = array(
                $where_son1,
                $where_son2,
                '_logic' => 'or'
            );
            $this->assign('query', $query);
        }
        $where['award.token'] = $this->wxuser['token'];
        $where['award.pid'] = $id;
        $where['award.zhongjiang'] = LotteryModel::ZHONGJIANG_ACTIVE;
        $where['award.status'] = array('neq', LotteryModel::AWARD_DELETE);
        $where['fans.pid'] = $id;
        $where['fans.status'] = LotteryModel::FANS_ACTIVE;
        $where['item.status'] = LotteryModel::ITEM_ACTIVE;
        $count = M('redpacket_fansaward')->alias('award')
            ->join('LEFT JOIN esm_redpacket_fans as fans ON fans.openid = award.openid')
            ->join('LEFT JOIN esm_redpacket_item as item ON item.id = award.award_id')
            ->where($where)
            ->count();
        $page = new Page($count, 15);
        $show = $page->show();
        $list = M('redpacket_fansaward')->alias('award')
            ->join('LEFT JOIN esm_redpacket_fans as fans ON fans.openid = award.openid')
            ->join('LEFT JOIN esm_redpacket_item as item ON item.id = award.award_id')
            ->where($where)
            ->limit($page->firstRow . ',' . $page->listRows)
            ->field('award.id,award.createdate,award.status,fans.name,fans.phone,fans.address,
                item.name as award_name,item.level')
            ->order('award.id desc')->select();
        if(!empty($list)){
            foreach ($list as &$value){
                $value['level_name'] = LotteryModel::getLevel($value['level']);
            }
        }
        $this->assign('lottery', $lottery);
        $this->assign('page', $show);
        $this->assign('list', $list);
        $this->assign('id', $id);
        $this->display('award_list');
    }

    public function statusAward()
    {
        $status = I('get.status', 'check', '');
        $condition['id'] = I('get.id', -1, '');
        if($status == 'check'){
            M('redpacket_fansaward')->where($condition)->save(array('status' => LotteryModel::AWARD_CHECKED));
            $message = '核销成功';
        }else{
            M('redpacket_fansaward')->where($condition)->save(array('status' => LotteryModel::AWARD_DELETE));
            $message = '删除成功';
        }
        $this->success($message, '', true);
    }

    public function statistics()
    {
        $id = I('get.id', -1, '');
        $where_lottery['id'] = $id;
        $lottery = M('redpacket')->where($where_lottery)->find();
        //奖项总量
        $where_item['redpacket_id'] = $id;
        $where_item['status'] = LotteryModel::ITEM_ACTIVE;
        $items = M('redpacket_item')->where($where_item)->select();
        $awardIds = $usedItems = $checkedItems = array();
        $award_record = '';
        if(!empty($items)){
            foreach ($items as $value){
                $awardIds[] = $value['id'];
            }
            //已消耗库存
            $where_used['pid'] = $id;
            $where_used['award_id'] = array('in', $awardIds);
            $where_used['zhongjiang'] = LotteryModel::ZHONGJIANG_ACTIVE;
            $where_used['status'] = array('neq', LotteryModel::AWARD_DELETE);
            $used = M('redpacket_fansaward')->where($where_used)->select();
            if(!empty($used)){
                foreach ($used as $value_used){
                    if($value_used['status'] == LotteryModel::AWARD_CHECKED){
                        $checkedItems[$value_used['award_id']]++;
                    }
                    $usedItems[$value_used['award_id']]++;
                }
                foreach ($items as $value){
                    $difference = $value['number'] - $usedItems[$value['id']];
                    $checked = isset($checkedItems[$value['id']]) ? $checkedItems[$value['id']] : 0;
                    $award_record .= LotteryModel::getLevel($value['level']).'已领：'.$usedItems[$value['id']]
                        .'份，剩余：'.$difference.'份，已核销：'.$checked.'份<br>';
                }
            }else{
                foreach ($items as $value){
                    $award_record .= LotteryModel::getLevel($value['level']).'已领：0份，剩余：'.$value['number']
                        .'份，已核销：0份<br>';
                }
            }
        }
        //折线图
        $range = date('Y-m-d', strtotime('-6 day')).' ~ '.date('Y-m-d');
        $range_date = I('get.range_date', $range, '');
        $this->assign('range_date', $range_date);
        $ranges = explode(' ~ ', $range_date);
        $start_time = strtotime($ranges[0]);
        $end_time = strtotime($ranges[1]);
        $start_date = date('Y-m-d H:i:s', $start_time);
        $end_date = date('Y-m-d H:i:s');
        $dateList = $list = array();
        while($start_time <= $end_time){
            $dateList[] = date('Y-m-d', $end_time);
            $end_time = $end_time - 3600 * 24;
        }
        krsort($dateList);
        //获奖人数
        $awardList = array();
        $where_award['pid'] = $id;
        $where_award['zhongjiang'] = LotteryModel::ZHONGJIANG_ACTIVE;
        $where_award['status'] = array('neq', LotteryModel::AWARD_DELETE);
        $where_award['createdate'] = array('between', array($start_date, $end_date));
        $awards = M("redpacket_fansaward")->where($where_award)->order('id desc')->select();
        if(!empty($awards)){
            foreach ($awards as $value) {
                $date = date('Y-m-d', strtotime($value['createdate']));
                $awardList[$date]++;
            }
        }
        //分享人数
        $shareList = array();
        $where_share["url"] = C('SITE_URL')."/Wap/Lottery/index?id=".$id;
        $where_share["reserve"] = $this->_project;
        $where_share["createdate"] = array('between', array($start_date, $end_date));
        $shares = M("wechat_share")->where($where_share)->order('shareId desc')->select();
        if(!empty($shares)){
            foreach ($shares as $value){
                $date = date('Y-m-d', strtotime($value['createdate']));
                $shareList[$date]++;
            }
        }
        $stats = StatisticsModel::getdaterange_list('lottery', $id, $ranges[0], $ranges[1]);
        $pv_num_count = $uv_num_count = $award_count = $share_count = 0;
        if(!empty($dateList)){
            foreach ($dateList as $value){
                $list[] = array(
                    'date' => date('m-d', strtotime($value)),
                    'pv' => isset($stats[$value]['pv_num']) ? $stats[$value]['pv_num'] : 0,
                    'uv' => isset($stats[$value]['uv_num']) ? $stats[$value]['uv_num'] : 0,
                    'award' => isset($awardList[$value]) ? $awardList[$value] : 0,
                    'share' => isset($shareList[$value]) ? $shareList[$value] : 0
                );
                if(isset($stats[$value]['pv_num'])) $pv_num_count += $stats[$value]['pv_num'];
                if(isset($stats[$value]['uv_num'])) $uv_num_count += $stats[$value]['uv_num'];
                if(isset($awardList[$value])) $award_count += $awardList[$value];
                if(isset($shareList[$value])) $share_count += $shareList[$value];
            }
        }
        $count = count($list);
        $list = json_encode($list);
        $this->assign('award_record', $award_record);
        $this->assign('count', $count);
        $this->assign('list', $list);
        $this->assign('id', $id);
        $this->assign('lottery', $lottery);
        $this->assign('pv_num_count', $pv_num_count);
        $this->assign('uv_num_count', $uv_num_count);
        $this->assign('award_count', $award_count);
        $this->assign('share_count', $share_count);
        $this->display();
    }

    public function exportStatistics()
    {
        set_time_limit(0);
        $id = I("get.id", -1, "");
        if($id == -1){
            $this->redirect("/User/Lottery/index");
        }
        vendor('phpexcel.PHPExcel');
        $objExcel = new \PHPExcel();
        $objActSheet = $objExcel->getActiveSheet();
        $objActSheet->getColumnDimension('A')->setWidth(30);
        $objActSheet->getColumnDimension('B')->setWidth(30);
        $objActSheet->getColumnDimension('C')->setWidth(30);
        $objActSheet->getColumnDimension('D')->setWidth(30);
        $objActSheet->getColumnDimension('E')->setWidth(30);
        $objActSheet->setCellValue('A1', "日期");
        $objActSheet->setCellValue('B1', "访客量");
        $objActSheet->setCellValue('C1', "访客数");
        $objActSheet->setCellValue('D1', "获奖人数");
        $objActSheet->setCellValue('E1', "分享人数");
        //统计折线图数据
        $range = date('Y-m-d', strtotime('-6 day')).' ~ '.date('Y-m-d');
        $range_date = I('get.range_date', $range, '');
        $ranges = explode(' ~ ', $range_date);
        $start_time = strtotime($ranges[0]);
        $end_time = strtotime($ranges[1]);
        $start_date = date('Y-m-d H:i:s', $start_time);
        $end_date = date('Y-m-d H:i:s');
        $dateList = $list = array();
        while($start_time <= $end_time){
            $dateList[] = date('Y-m-d', $end_time);
            $end_time = $end_time - 3600 * 24;
        }
        krsort($dateList);
        //获奖人数
        $awardList = array();
        $where_award['pid'] = $id;
        $where_award['zhongjiang'] = LotteryModel::ZHONGJIANG_ACTIVE;
        $where_award['status'] = array('neq', LotteryModel::AWARD_DELETE);
        $where_award['createdate'] = array('between', array($start_date, $end_date));
        $awards = M("redpacket_fansaward")->where($where_award)->order('id desc')->select();
        if(!empty($awards)){
            foreach ($awards as $value) {
                $date = date('Y-m-d', strtotime($value['createdate']));
                $awardList[$date]++;
            }
        }
        //分享人数
        $shareList = array();
        $where_share["url"] = C('SITE_URL')."/Wap/Lottery/index?id=".$id;
        $where_share["reserve"] = $this->_project;
        $where_share["createdate"] = array('between', array($start_date, $end_date));
        $shares = M("wechat_share")->where($where_share)->order('shareId desc')->select();
        if(!empty($shares)){
            foreach ($shares as $value){
                $date = date('Y-m-d', strtotime($value['createdate']));
                $shareList[$date]++;
            }
        }
        $stats = StatisticsModel::getdaterange_list('lottery', $id, $ranges[0], $ranges[1]);
        if(!empty($dateList)){
            foreach ($dateList as $value){
                $list[] = array(
                    'date' => date('m-d', strtotime($value)),
                    'pv' => isset($stats[$value]['pv_num']) ? $stats[$value]['pv_num'] : 0,
                    'uv' => isset($stats[$value]['uv_num']) ? $stats[$value]['uv_num'] : 0,
                    'award' => isset($awardList[$value]) ? $awardList[$value] : 0,
                    'share' => isset($shareList[$value]) ? $shareList[$value] : 0
                );
            }
        }
        $line = 2;
        if(!empty($list)){
            foreach ($list as $value) {
                $objActSheet->setCellValue('A' . $line, $value['date']);
                $objActSheet->setCellValue('B' . $line, $value['pv']);
                $objActSheet->setCellValue('C' . $line, $value['uv']);
                $objActSheet->setCellValue('D' . $line, $value['award']);
                $objActSheet->setCellValue('E' . $line, $value['share']);
                $objActSheet->getRowDimension($line)->setRowHeight(20);
                $line++;
            }
        }
        $fileName = '活动数据' . date('Ymd') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=\"$fileName\"");
        header('Cache-Control: max-age=0');
        $objWriter = new \PHPExcel_Writer_Excel2007($objExcel);
        $objWriter->save('php://output');
    }

    public function statisticsUser()
    {
        $id = I('get.id', -1, '');
        $where_lottery['id'] = $id;
        $lottery = M('redpacket')->where($where_lottery)->find();
        $sexStr = $cityStr = $phoneStr = '';
        $sexArr = $cityArr = $phoneArr = $cityRank = array();
        //用户性别、城市、手机设备
        $where_fans['pid'] = $id;
        $where_fans['status'] = LotteryModel::FANS_ACTIVE;
        $fans = M('redpacket_fans')->where($where_fans)->field('sex,phone_type,city')->select();
        if(!empty($fans)){
            foreach ($fans as $value){
                $sexArr[$value['sex']]++;
                $cityArr[$value['city']]++;
                $phoneArr[$value['phone_type']]++;
            }
            krsort($sexArr);
            arsort($cityArr);
            arsort($phoneArr);
            if(!empty($sexArr)){
                foreach ($sexArr as $key => $value){
                    if($key == 1){
                        $sexStr .= '{y: '.$value.', name: "男"},';
                    }elseif($key == 2){
                        $sexStr .= '{y: '.$value.', name: "女", sliced: true, selected: true},';
                    }else{
                        $sexStr .= '{y: '.$value.', name: "未知"},';
                    }
                }
            }
            if(!empty($cityArr)){
                $i = 1;
                foreach ($cityArr as $key => $value){
                    if($key != '未知'){
                        $cityRank[] = array('name' => $key, 'value' => $value);
                    }
                    if($i == 1){
                        $cityStr .= '{y: '.$value.', name: "'.$key.'", sliced: true, selected: true},';
                    }else{
                        $cityStr .= '{y: '.$value.', name: "'.$key.'"},';
                    }
                    $i++;
                }
            }
            if(!empty($phoneArr)){
                $j = 1;
                foreach ($phoneArr as $key => $value){
                    if($j == 1){
                        $phoneStr .= '{y: '.$value.', name: "'.$key.'", sliced: true, selected: true},';
                    }else{
                        $phoneStr .= '{y: '.$value.', name: "'.$key.'"},';
                    }
                    $j++;
                }
            }
        }
        $this->assign('id', $id);
        $this->assign('lottery', $lottery);
        $this->assign('sexStr', $sexStr);
        $this->assign('cityStr', $cityStr);
        $this->assign('phoneStr', $phoneStr);
        $this->assign('cityRank', $cityRank);
        $this->display('statistics_user');
    }
    //todo 缩小后台宽度样式变化
    //ajax php 不统一
}